import config from './config'

export default (opts = {}, successCallback, errorCallback) => {

  opts = $.extend({
    type: 'POST',
    dataType: 'json',
    success: resp => {
      if (resp && 0 === resp.code) {
        successCallback && successCallback(resp)
      } else {
        successCallback && successCallback(false)
      }
    },
    fail: (resp) => {
      errorCallback && errorCallback(resp)
    }
  }, opts, {
    url: `/${config.project}` + opts.url
  })

  return $.ajax(opts)

}

